﻿using Basic.Traceability.ErrorCode;
using Basic.Traceability.Host.Api.Read.Application.Command.Products.TraceableProducts;
using Basic.Traceability.Host.Api.Read.Application.Command.User;
using Basic.Traceability.Host.Api.Read.Dto;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Basic.Traceability.Host.Api.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TracebilityController : ControllerBase
    {
        private readonly IMediator mediator;

        public TracebilityController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取商品信息列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIPaging<TraceableProductsDto>> GetTraceableProductsList([FromQuery] GetTraceableProductsListCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<UserDto>> Login([FromQuery] LoginCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询产品基本信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<TraceableProductsDto>>> GetTraceProducts([FromQuery] GetTraceProductsCommand request)
        {
            return mediator.Send(request);
        }
    }
}
